
import http from './http'
import filters from './filters'
import './directive'

const install = (Vue) => {
	Vue.prototype.$http = http

	const apisFiles = require.context('./apis', true, /.js$/)
	Vue.prototype.$apis = apisFiles.keys().reduce((apis, apiPath) => {
		const apiName = apiPath.replace(/^.\/(.*)\.js/,'$1')
		const value = apisFiles(apiPath)
		apis[apiName] = value.default
  	return apis
  }, {})

	const utilsFiles = require.context('./utils', true, /.js$/)
	Vue.prototype.$utils = utilsFiles.keys().reduce((utils, utilPath) => {
		const utilName = utilPath.replace(/^.\/(.*)\.js/,'$1')
		const value = utilsFiles(utilPath)
		utils[utilName] = value.default
  	return utils
  }, {})

	Vue.use(filters)
}

export default {
	install
}